home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / slavebase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  27.4 KB  |  842 lines

  1. /*
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __slavebase_h
  21. #define __slavebase_h
  22.  
  23. #include <kurl.h>
  24. #include <kconfigbase.h>
  25. #include <kio/global.h>
  26. #include <kio/authinfo.h>
  27.  
  28. class DCOPClient;
  29. class KRemoteEncoding;
  30.  
  31. namespace KIO {
  32.  
  33. class Connection;
  34. class SlaveBasePrivate;
  35.  
  36. /**
  37.  * There are two classes that specifies the protocol between application (job)
  38.  * and kioslave. SlaveInterface is the class to use on the application end,
  39.  * SlaveBase is the one to use on the slave end.
  40.  *
  41.  * Slave implementations should simply inherit SlaveBase
  42.  *
  43.  * A call to foo() results in a call to slotFoo() on the other end.
  44.  */
  45. class KIO_EXPORT SlaveBase
  46. {
  47. public:
  48.     SlaveBase( const QCString &protocol, const QCString &pool_socket, const QCString &app_socket);
  49.     virtual ~SlaveBase();
  50.  
  51.     /**
  52.      * @internal
  53.      * Terminate the slave by calling the destructor and then ::exit()
  54.      */
  55.     void exit();
  56.  
  57.     /**
  58.      * @internal
  59.      */
  60.     void dispatchLoop();
  61.  
  62.     /**
  63.      * @internal
  64.      */
  65.     void setConnection( Connection* connection ) { m_pConnection = connection; }
  66.     /**
  67.      * @internal
  68.      */
  69.     Connection *connection() const { return m_pConnection; }
  70.  
  71.  
  72.     ///////////
  73.     // Message Signals to send to the job
  74.     ///////////
  75.  
  76.     /**
  77.      * Sends data in the slave to the job (i.e. in get).
  78.      *
  79.      * To signal end of data, simply send an empty
  80.      * QByteArray().
  81.      *
  82.      * @param data the data read by the slave
  83.      */
  84.     void data( const QByteArray &data );
  85.  
  86.     /**
  87.      * Asks for data from the job.
  88.      * @see readData
  89.      */
  90.     void dataReq( );
  91.  
  92.     /**
  93.      * Call to signal an error.
  94.      * This also finishes the job, no need to call finished.
  95.      *
  96.      * If the Error code is KIO::ERR_SLAVE_DEFINED then the
  97.      * _text should contain the complete translated text of
  98.      * of the error message.  This message will be displayed
  99.      * in an KTextBrowser which allows rich text complete
  100.      * with hyper links.  Email links will call the default
  101.      * mailer, "exec:/command arg1 arg2" will be forked and
  102.      * all other links will call the default browser.
  103.      *
  104.      * @see KIO::Error
  105.      * @see KTextBrowser
  106.      * @param _errid the error code from KIO::Error
  107.      * @param _text the rich text error message
  108.      */
  109.     void error( int _errid, const QString &_text );
  110.  
  111.     /**
  112.      * Call in openConnection, if you reimplement it, when you're done.
  113.      */
  114.     void connected();
  115.  
  116.     /**
  117.      * Call to signal successful completion of any command
  118.      * (besides openConnection and closeConnection)
  119.      */
  120.     void finished();
  121.  
  122.     /**
  123.      * Call to signal that data from the sub-URL is needed
  124.      */
  125.     void needSubURLData();
  126.  
  127.     /**
  128.      * Used to report the status of the slave.
  129.      * @param host the slave is currently connected to. (Should be
  130.      *        empty if not connected)
  131.      * @param connected Whether an actual network connection exists.
  132.      **/
  133.     void slaveStatus(const QString &host, bool connected);
  134.  
  135.     /**
  136.      * Call this from stat() to express details about an object, the
  137.      * UDSEntry customarily contains the atoms describing file name, size,
  138.      * mimetype, etc.
  139.      * @param _entry The UDSEntry containing all of the object attributes.
  140.      */
  141.     void statEntry( const UDSEntry& _entry );
  142.  
  143.     /**
  144.      * Call this in listDir, each time you have a bunch of entries
  145.      * to report.
  146.      * @param _entry The UDSEntry containing all of the object attributes.
  147.      */
  148.     void listEntries( const UDSEntryList& _entry );
  149.  
  150.     /**
  151.      * Call this at the beginning of put(), to give the size of the existing
  152.      * partial file, if there is one. The @p offset argument notifies the
  153.      * other job (the one that gets the data) about the offset to use.
  154.      * In this case, the boolean returns whether we can indeed resume or not
  155.      * (we can't if the protocol doing the get() doesn't support setting an offset)
  156.      */
  157.     bool canResume( KIO::filesize_t offset );
  158.  
  159.     /*
  160.      * Call this at the beginning of get(), if the "resume" metadata was set
  161.      * and resuming is implemented by this protocol.
  162.      */
  163.     void canResume();
  164.  
  165.     ///////////
  166.     // Info Signals to send to the job
  167.     ///////////
  168.  
  169.     /**
  170.      * Call this in get and copy, to give the total size
  171.      * of the file
  172.      * Call in listDir too, when you know the total number of items.
  173.      */
  174.     void totalSize( KIO::filesize_t _bytes );
  175.     /**
  176.      * Call this during get and copy, once in a while,
  177.      * to give some info about the current state.
  178.      * Don't emit it in listDir, listEntries speaks for itself.
  179.      */
  180.     void processedSize( KIO::filesize_t _bytes );
  181.  
  182.     /**
  183.      * Only use this if you can't know in advance the size of the
  184.      * copied data. For example, if you're doing variable bitrate
  185.      * compression of the source.
  186.      *
  187.      * STUB ! Currently unimplemented. Here now for binary compatibility.
  188.      *
  189.      * Call this during get and copy, once in a while,
  190.      * to give some info about the current state.
  191.      * Don't emit it in listDir, listEntries speaks for itself.
  192.      */
  193.     void processedPercent( float percent );
  194.  
  195.     /**
  196.      * Call this in get and copy, to give the current transfer
  197.      * speed, but only if it can't be calculated out of the size you
  198.      * passed to processedSize (in most cases you don't want to call it)
  199.      */
  200.     void speed( unsigned long _bytes_per_second );
  201.  
  202.     /**
  203.      * Call this to signal a redirection
  204.      * The job will take care of going to that url.
  205.      */
  206.     void redirection( const KURL &_url );
  207.  
  208.     /**
  209.      * Tell that we will only get an error page here.
  210.      * This means: the data you'll get isn't the data you requested,
  211.      * but an error page (usually HTML) that describes an error.
  212.      */
  213.     void errorPage();
  214.  
  215.     /**
  216.      * Call this in mimetype() and in get(), when you know the mimetype.
  217.      * See mimetype about other ways to implement it.
  218.      */
  219.     void mimeType( const QString &_type );
  220.  
  221.     /**
  222.      * Call to signal a warning, to be displayed in a dialog box.
  223.      */
  224.     void warning( const QString &msg );
  225.  
  226.     /**
  227.      * Call to signal a message, to be displayed if the application wants to,
  228.      * for instance in a status bar. Usual examples are "connecting to host xyz", etc.
  229.      */
  230.     void infoMessage( const QString &msg );
  231.  
  232.     enum MessageBoxType { QuestionYesNo = 1, WarningYesNo = 2, WarningContinueCancel = 3, WarningYesNoCancel = 4, Information = 5, SSLMessageBox = 6 };
  233.  
  234.     /**
  235.      * Call this to show a message box from the slave
  236.      * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
  237.      * @param text Message string. May contain newlines.
  238.      * @param caption Message box title.
  239.      * @param buttonYes The text for the first button.
  240.      *                  The default is i18n("&Yes").
  241.      * @param buttonNo  The text for the second button.
  242.      *                  The default is i18n("&No").
  243.      * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused.
  244.      *       and for Information, none is used.
  245.      * @return a button code, as defined in KMessageBox, or 0 on communication error.
  246.      */
  247.     int messageBox( MessageBoxType type, const QString &text,
  248.                     const QString &caption = QString::null,
  249.                     const QString &buttonYes = QString::null,
  250.                     const QString &buttonNo = QString::null );
  251.  
  252.     /**
  253.      * Call this to show a message box from the slave
  254.      * @param text Message string. May contain newlines.
  255.      * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
  256.      * @param caption Message box title.
  257.      * @param buttonYes The text for the first button.
  258.      *                  The default is i18n("&Yes").
  259.      * @param buttonNo  The text for the second button.
  260.      *                  The default is i18n("&No").
  261.      * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused.
  262.      *       and for Information, none is used.
  263.      * @param dontAskAgainName A checkbox is added with which further confirmation can be turned off.
  264.      *        The string is used to lookup and store the setting in kioslaverc.
  265.      * @return a button code, as defined in KMessageBox, or 0 on communication error.
  266.      * @since 3.3
  267.      */
  268.     int messageBox( const QString &text, MessageBoxType type,
  269.                     const QString &caption = QString::null,
  270.                     const QString &buttonYes = QString::null,
  271.                     const QString &buttonNo = QString::null,
  272.                     const QString &dontAskAgainName = QString::null );
  273.  
  274.     /**
  275.      * Sets meta-data to be send to the application before the first
  276.      * data() or finished() signal.
  277.      */
  278.     void setMetaData(const QString &key, const QString &value);
  279.  
  280.     /**
  281.      * Queries for the existence of a certain config/meta-data entry
  282.      * send by the application to the slave.
  283.      * @since 3.2
  284.      */
  285.     bool hasMetaData(const QString &key) const;
  286.  
  287.     /**
  288.      * Queries for config/meta-data send by the application to the slave.
  289.      * @since 3.2
  290.      */
  291.     QString metaData(const QString &key) const;
  292.  
  293.     /**
  294.      * @obsolete kept for binary compatibility
  295.      * Queries for the existence of a certain config/meta-data entry
  296.      * send by the application to the slave.
  297.      */
  298.     bool hasMetaData(const QString &key);
  299.  
  300.     /**
  301.      * @obsolete kept for binary compatibility
  302.      * Queries for config/meta-data sent by the application to the slave.
  303.      */
  304.     QString metaData(const QString &key);
  305.  
  306.     /**
  307.      * @internal for ForwardingSlaveBase
  308.      * Contains all metadata (but no config) sent by the application to the slave.
  309.      * @since 3.5.2
  310.      */
  311.     MetaData allMetaData() const { return mIncomingMetaData; }
  312.  
  313.     /**
  314.      * Returns a configuration object to query config/meta-data information
  315.      * from.
  316.      *
  317.      * The application provides the slave with all configuration information
  318.      * relevant for the current protocol and host.
  319.      */
  320.     KConfigBase* config();
  321.  
  322.     /**
  323.      * Returns an object that can translate remote filenames into proper
  324.      * Unicode forms. This encoding can be set by the user.
  325.      *
  326.      * @since 3.3
  327.      */
  328.     KRemoteEncoding* remoteEncoding();
  329.  
  330.  
  331.     ///////////
  332.     // Commands sent by the job, the slave has to
  333.     // override what it wants to implement
  334.     ///////////
  335.  
  336.     /**
  337.      * Set the host
  338.      * @param host
  339.      * @param port
  340.      * @param user
  341.      * @param pass
  342.      * Called directly by createSlave, this is why there is no equivalent in
  343.      * SlaveInterface, unlike the other methods.
  344.      *
  345.      * This method is called whenever a change in host, port or user occurs.
  346.      */
  347.     virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
  348.  
  349.     /**
  350.      * Prepare slave for streaming operation
  351.      */
  352.     virtual void setSubURL(const KURL&url);
  353.  
  354.     /**
  355.      * Opens the connection (forced)
  356.      * When this function gets called the slave is operating in
  357.      * connection-oriented mode.
  358.      * When a connection gets lost while the slave operates in
  359.      * connection oriented mode, the slave should report
  360.      * ERR_CONNECTION_BROKEN instead of reconnecting. The user is
  361.      * expected to disconnect the slave in the error handler.
  362.      */
  363.     virtual void openConnection();
  364.  
  365.     /**
  366.      * Closes the connection (forced)
  367.      * Called when the application disconnects the slave to close
  368.      * any open network connections.
  369.      *
  370.      * When the slave was operating in connection-oriented mode,
  371.      * it should reset itself to connectionless (default) mode.
  372.      */
  373.     virtual void closeConnection();
  374.  
  375.     /**
  376.      * get, aka read.
  377.      * @param url the full url for this request. Host, port and user of the URL
  378.      *        can be assumed to be the same as in the last setHost() call.
  379.      * The slave emits the data through data
  380.      */
  381.     virtual void get( const KURL& url );
  382.  
  383.     /**
  384.      * put, i.e. write data into a file.
  385.      *
  386.      * @param url where to write the file
  387.      * @param permissions may be -1. In this case no special permission mode is set.
  388.      * @param overwrite if true, any existing file will be overwritten.
  389.      * If the file indeed already exists, the slave should NOT apply the
  390.      * permissions change to it.
  391.      * @param resume currently unused, please ignore.
  392.      *   The support for resuming using .part files is done by calling canResume().
  393.      *
  394.      * IMPORTANT: Use the "modified" metadata in order to set the modification time of the file.
  395.      *
  396.      * @see canResume()
  397.      */
  398.     virtual void put( const KURL& url, int permissions, bool overwrite, bool resume );
  399.  
  400.     /**
  401.      * Finds all details for one file or directory.
  402.      * The information returned is the same as what listDir returns,
  403.      * but only for one file or directory.
  404.      */
  405.     virtual void stat( const KURL& url );
  406.  
  407.     /**
  408.      * Finds mimetype for one file or directory.
  409.      *
  410.      * This method should either emit 'mimeType' or it
  411.      * should send a block of data big enough to be able
  412.      * to determine the mimetype.
  413.      *
  414.      * If the slave doesn't reimplement it, a get will
  415.      * be issued, i.e. the whole file will be downloaded before
  416.      * determining the mimetype on it - this is obviously not a
  417.      * good thing in most cases.
  418.      */
  419.     virtual void mimetype( const KURL& url );
  420.  
  421.     /**
  422.      * Lists the contents of @p url.
  423.      * The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist,
  424.      * if we don't have enough permissions, or if it is a file
  425.      * It should also emit totalFiles as soon as it knows how many
  426.      * files it will list.
  427.      */
  428.     virtual void listDir( const KURL& url );
  429.  
  430.     /**
  431.      * Create a directory
  432.      * @param url path to the directory to create
  433.      * @param permissions the permissions to set after creating the directory
  434.      * (-1 if no permissions to be set)
  435.      * The slave emits ERR_COULD_NOT_MKDIR if failure.
  436.      */
  437.     virtual void mkdir( const KURL&url, int permissions );
  438.  
  439.     /**
  440.      * Rename @p oldname into @p newname.
  441.      * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
  442.      * ask for copy + del instead.
  443.      * @param src where to move the file from
  444.      * @param dest where to move the file to
  445.      * @param overwrite if true, any existing file will be overwritten
  446.      */
  447.     virtual void rename( const KURL& src, const KURL& dest, bool overwrite );
  448.  
  449.     /**
  450.      * Creates a symbolic link named @p dest, pointing to @p target, which
  451.      * may be a relative or an absolute path.
  452.      * @param target The string that will become the "target" of the link (can be relative)
  453.      * @param dest The symlink to create.
  454.      * @param overwrite whether to automatically overwrite if the dest exists
  455.      */
  456.     virtual void symlink( const QString& target, const KURL& dest, bool overwrite );
  457.  
  458.     /**
  459.      * Change permissions on @p path
  460.      * The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD
  461.      */
  462.     virtual void chmod( const KURL& url, int permissions );
  463.  
  464.     /**
  465.      * Copy @p src into @p dest.
  466.      * If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
  467.      * ask for get + put instead.
  468.      * @param src where to copy the file from (decoded)
  469.      * @param dest where to copy the file to (decoded)
  470.      * @param permissions may be -1. In this case no special permission mode is set.
  471.      * @param overwrite if true, any existing file will be overwritten
  472.      *
  473.      */
  474.     virtual void copy( const KURL &src, const KURL &dest, int permissions, bool overwrite );
  475.  
  476.     /**
  477.      * Delete a file or directory.
  478.      * @param url file/directory to delete
  479.      * @param isfile if true, a file should be deleted.
  480.      *               if false, a directory should be deleted.
  481.      */
  482.     virtual void del( const KURL &url, bool isfile);
  483.  
  484.     // TODO KDE4: add setLinkDest() or something, to modify symlink targets.
  485.     // Will be used for kio_file but also kio_remote (#97129)
  486.  
  487.     /**
  488.      * Used for any command that is specific to this slave (protocol)
  489.      * Examples are : HTTP POST, mount and unmount (kio_file)
  490.      *
  491.      * @param data packed data; the meaning is completely dependent on the
  492.      *        slave, but usually starts with an int for the command number.
  493.      * Document your slave's commands, at least in its header file.
  494.      */
  495.     virtual void special( const QByteArray & data );
  496.  
  497.     /**
  498.      * Used for multiple get. Currently only used foir HTTP pielining
  499.      * support.
  500.      *
  501.      * @param data packed data; Contains number of URLs to fetch, and for
  502.      * each URL the URL itself and its associated MetaData.
  503.      */
  504.     virtual void multiGet( const QByteArray & data );
  505.  
  506.     /**
  507.      * Called to get the status of the slave. Slave should respond
  508.      * by calling slaveStatus(...)
  509.      */
  510.     virtual void slave_status();
  511.  
  512.     /**
  513.      * Called by the scheduler to tell the slave that the configuration
  514.      * changed (i.e. proxy settings) .
  515.      */
  516.     virtual void reparseConfiguration();
  517.  
  518.  
  519.     /**
  520.      * @return timeout value for connecting to remote host.
  521.      */
  522.     int connectTimeout();
  523.  
  524.     /**
  525.      * @return timeout value for connecting to proxy in secs.
  526.      */
  527.     int proxyConnectTimeout();
  528.  
  529.     /**
  530.      * @return timeout value for read from first data from
  531.      * remote host in seconds.
  532.      */
  533.     int responseTimeout();
  534.  
  535.     /**
  536.      * @return timeout value for read from subsequent data from
  537.      * remote host in secs.
  538.      */
  539.     int readTimeout();
  540.  
  541.     /**
  542.      * This function sets a timeout of @p timeout seconds and calls
  543.      * special(data) when the timeout occurs as if it was called by the
  544.      * application.
  545.      *
  546.      * A timeout can only occur when the slave is waiting for a command
  547.      * from the application.
  548.      *
  549.      * Specifying a negative timeout cancels a pending timeout.
  550.      *
  551.      * Only one timeout at a time is supported, setting a timeout
  552.      * cancels any pending timeout.
  553.      * @since 3.1
  554.      */
  555.     void setTimeoutSpecialCommand(int timeout, const QByteArray &data=QByteArray());
  556.  
  557.     /**
  558.      * @internal
  559.      */
  560.     static void sigsegv_handler(int);
  561.     /**
  562.      * @internal
  563.      */
  564.     static void sigpipe_handler(int);
  565.  
  566.     /////////////////
  567.     // Dispatching (internal)
  568.     ////////////////
  569.  
  570.     /**
  571.      * @internal
  572.      */
  573.     virtual bool dispatch();
  574.     /**
  575.      * @internal
  576.      */
  577.     virtual void dispatch( int command, const QByteArray &data );
  578.  
  579.     /**
  580.      * Read data send by the job, after a dataReq
  581.      *
  582.      * @param buffer buffer where data is stored
  583.      * @return 0 on end of data,
  584.      *         > 0 bytes read
  585.      *         < 0 error
  586.      **/
  587.     int readData( QByteArray &buffer );
  588.  
  589.     /**
  590.      * internal function to be called by the slave.
  591.      * It collects entries and emits them via listEntries
  592.      * when enough of them are there or a certain time
  593.      * frame exceeded (to make sure the app gets some
  594.      * items in time but not too many items one by one
  595.      * as this will cause a drastic performance penalty)
  596.      * @param _entry The UDSEntry containing all of the object attributes.
  597.      * @param ready set to true after emitting all items. @p _entry is not
  598.      *        used in this case
  599.      */
  600.     void listEntry( const UDSEntry& _entry, bool ready);
  601.  
  602.     /**
  603.      * internal function to connect a slave to/ disconnect from
  604.      * either the slave pool or the application
  605.      */
  606.     void connectSlave(const QString& path);
  607.     void disconnectSlave();
  608.  
  609.     /**
  610.      * Prompt the user for Authorization info (login & password).
  611.      *
  612.      * Use this function to request authorization information from
  613.      * the end user. You can also pass an error message which explains
  614.      * why a previous authorization attempt failed. Here is a very
  615.      * simple example:
  616.      *
  617.      * \code
  618.      * KIO::AuthInfo authInfo;
  619.      * if ( openPassDlg( authInfo ) )
  620.      * {
  621.      *    kdDebug() << QString::fromLatin1("User: ")
  622.      *              << authInfo.username << endl;
  623.      *    kdDebug() << QString::fromLatin1("Password: ")
  624.      *              << QString::fromLatin1("Not displayed here!") << endl;
  625.      * }
  626.      * \endcode
  627.      *
  628.      * You can also preset some values like the username, caption or
  629.      * comment as follows:
  630.      *
  631.      * \code
  632.      * KIO::AuthInfo authInfo;
  633.      * authInfo.caption= "Acme Password Dialog";
  634.      * authInfo.username= "Wile E. Coyote";
  635.      * QString errorMsg = "You entered an incorrect password.";
  636.      * if ( openPassDlg( authInfo, errorMsg ) )
  637.      * {
  638.      *    kdDebug() << QString::fromLatin1("User: ")
  639.      *              << authInfo.username << endl;
  640.      *    kdDebug() << QString::fromLatin1("Password: ")
  641.      *              << QString::fromLatin1("Not displayed here!") << endl;
  642.      * }
  643.      * \endcode
  644.      *
  645.      * \note You should consider using checkCachedAuthentication() to
  646.      * see if the password is available in kpasswdserver before calling
  647.      * this function.
  648.      *
  649.      * \note A call to this function can fail and return @p false,
  650.      * if the UIServer could not be started for whatever reason.
  651.      *
  652.      * @see checkCachedAuthentication
  653.      * @param info  See AuthInfo.
  654.      * @param errorMsg Error message to show
  655.      * @return      @p true if user clicks on "OK", @p false otherwsie.
  656.      * @since 3.1
  657.      */
  658.     bool openPassDlg( KIO::AuthInfo& info, const QString &errorMsg );
  659.  
  660.     /**
  661.      * Same as above function except it does not need error message.
  662.      * BIC: Combine this function with the above for KDE4.
  663.      */
  664.     bool openPassDlg( KIO::AuthInfo& info );
  665.  
  666.     /**
  667.      * Checks for cached authentication based on parameters
  668.      * given by @p info.
  669.      *
  670.      * Use this function to check if any cached password exists
  671.      * for the URL given by @p info.  If @p AuthInfo::realmValue
  672.      * and/or @p AuthInfo::verifyPath flag is specified, then
  673.      * they will also be factored in determining the presence
  674.      * of a cached password.  Note that @p Auth::url is a required
  675.      * parameter when attempting to check for cached authorization
  676.      * info. Here is a simple example:
  677.      *
  678.      * \code
  679.      * AuthInfo info;
  680.      * info.url = KURL("http://www.foobar.org/foo/bar");
  681.      * info.username = "somename";
  682.      * info.verifyPath = true;
  683.      * if ( !checkCachedAuthentication( info ) )
  684.      * {
  685.      *    if ( !openPassDlg(info) )
  686.      *     ....
  687.      * }
  688.      * \endcode
  689.      *
  690.      * @param       info See AuthInfo.
  691.      * @return      @p true if cached Authorization is found, false otherwise.
  692.      */
  693.     bool checkCachedAuthentication( AuthInfo& info );
  694.  
  695.     /**
  696.      * Explicitly store authentication information. openPassDlg already
  697.      * stores password information automatically, you only need to call
  698.      * this function if you want to store authentication information that
  699.      * is different from the information returned by openPassDlg.
  700.      */
  701.     bool cacheAuthentication( const AuthInfo& info );
  702.  
  703.     /**
  704.      * @obsolete as of 3.1.
  705.      * TODO: Remove before KDE 4.0
  706.      */
  707.     bool pingCacheDaemon() const;
  708.  
  709.     /**
  710.      * @obsolete as of 3.1. Use openPassDlg instead.
  711.      * TODO: Remove before KDE 4.0
  712.      * Creates a basic key to be used to cache the password.
  713.      * @param url   the url from which the key is supposed to be generated
  714.      */
  715.     QString createAuthCacheKey( const KURL& url );
  716.  
  717.     /**
  718.      * @obsolete as of 3.1. Use openPassDlg instead.
  719.      * TODO: Remove before KDE 4.0
  720.      *
  721.      * Cache authentication information is now stored automatically
  722.      * by openPassDlg.
  723.      */
  724.     void sendAuthenticationKey( const QCString& gKey, const QCString& key, bool keep );
  725.  
  726.     /**
  727.      * @obsolete as of 3.1. Use openPassDlg instead.
  728.      * TODO: Remove before KDE 4.0
  729.      *
  730.      * Cached authentication information is now session based and
  731.      * removed automatically when a given session ends, i.e. the
  732.      * application is closed.
  733.      */
  734.     void delCachedAuthentication( const QString& key );
  735.  
  736.     /**
  737.      * @obsolete as of 3.1. Use openPassDlg instead.
  738.      * TODO: Remove before KDE 4.0
  739.      */
  740.     void setMultipleAuthCaching( bool ) {};
  741.  
  742.     /**
  743.      * @obsolete as of 3.1. Use openPassDlg instead.
  744.      * TODO: Remove before KDE 4.0
  745.      */
  746.     bool multipleAuthCaching() const { return false; }
  747.  
  748.     /**
  749.      * Used by the slave to check if it can connect
  750.      * to a given host. This should be called where the slave is ready
  751.      * to do a ::connect() on a socket. For each call to
  752.      * requestNetwork must exist a matching call to
  753.      * dropNetwork, or the system will stay online until
  754.      * KNetMgr gets closed (or the SlaveBase gets destructed)!
  755.      *
  756.      * If KNetMgr is not running, then this is a no-op and returns true
  757.      *
  758.      * @param host tells the netmgr the host the slave wants to connect
  759.      *             to. As this could also be a proxy, we can't just take
  760.      *             the host currenctly connected to (but that's the default
  761.      *             value)
  762.      *
  763.      * @return true in theorie, the host is reachable
  764.      *         false the system is offline and the host is in a remote network.
  765.      */
  766.     bool requestNetwork(const QString& host = QString::null);
  767.  
  768.     /**
  769.      * Used by the slave to withdraw a connection requested by
  770.      * requestNetwork. This function cancels the last call to
  771.      * requestNetwork. If a client uses more than one internet
  772.      * connection, it must use dropNetwork(host) to
  773.      * stop each request.
  774.      *
  775.      * If KNetMgr is not running, then this is a no-op.
  776.      *
  777.      * @param host the host passed to requestNetwork
  778.      *
  779.      * A slave should call this function every time it disconnect from a host.
  780.      * */
  781.     void dropNetwork(const QString& host = QString::null);
  782.  
  783.     /**
  784.      * Return the dcop client used by this slave.
  785.      * @since 3.1
  786.      */
  787.     DCOPClient *dcopClient();
  788.  
  789.     /**
  790.      * Wait for an answer to our request, until we get @p expected1 or @p expected2
  791.      * @return the result from readData, as well as the cmd in *pCmd if set, and the data in @p data
  792.      */
  793.     int waitForAnswer( int expected1, int expected2, QByteArray & data, int * pCmd = 0 );
  794.  
  795.     /**
  796.      * Internal function to transmit meta data to the application.
  797.      */
  798.     void sendMetaData();
  799.  
  800.     /**
  801.      * Name of the protocol supported by this slave
  802.      */
  803.     QCString mProtocol;
  804.  
  805.     Connection * m_pConnection;
  806.  
  807.     MetaData mOutgoingMetaData;
  808.     MetaData mIncomingMetaData;
  809.  
  810.     /** If your ioslave was killed by a signal, wasKilled() returns true.
  811.      Check it regularly in lengthy functions (e.g. in get();) and return
  812.      as fast as possible from this function if wasKilled() returns true.
  813.      This will ensure that your slave destructor will be called correctly.
  814.      @since 3.1
  815.      */
  816.     bool wasKilled() const;
  817.  
  818.     /** Internally used.
  819.      * @internal
  820.      * @since 3.1
  821.      */
  822.     void setKillFlag();
  823.  
  824. protected:
  825.     UDSEntryList pendingListEntries;
  826.     uint listEntryCurrentSize;
  827.     long listEntry_sec, listEntry_usec;
  828.     Connection *appconn;
  829.     QString mPoolSocket;
  830.     QString mAppSocket;
  831.     bool mConnectedToApp;
  832.     static long s_seqNr;
  833.     virtual void virtual_hook( int id, void* data );
  834.  
  835. private:
  836.     SlaveBasePrivate *d;
  837. };
  838.  
  839. }
  840.  
  841. #endif
  842.